// JavaScript Document

$(document).ready(function(){
	// set AJAX properties and query string variables for curl.php
	function yqlRequest(url, parser){
		$.ajax({
			type: "GET",
			url: "php/yql.php",
			dataType: "xml",
			data: {
				url: url,
			},
			success: parser
		}); // close ajax
	}

  function parseBLOG(xml) {
    $(xml).find('entry').each(function () {
        var title = $(this).find('title').text();
            date = $(this).find('published').text();
		    content = $(this).find('content').text();
	        postLink = $(this).find('link:[rel="alternate"]').attr('href');

        var html = '<div class="entry"><h2 class="title"><a href="' + postLink +'">' + title + '</a></h2>';
    	    html += '<div class="postContent">' + content + '</div>';
	        html += '</div>';
	
	  $('#main').append(html);
	  
    });
  }
  
  $('a#home').click(function(mouseEvent){
    mouseEvent.preventDefault();
    
	var url = 'http://query.yahooapis.com/v1/public/yql?q=select%20entry%20from%20xml%20where%20url%3D%22http%3A%2F%2Ftrevorburkholder.blogspot.com%2Ffeeds%2Fposts%2Fdefault%22&diagnostics=true';
	    parser = parseBLOG;
		
	yqlRequest(url, parser); 
	
    return false;
  });
  
});